<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--
  ~ Copyright (c) 2013-2015 Charkey. All rights reserved.
  ~
  ~ This software is the confidential and proprietary information of Charkey.
  ~ You shall not disclose such Confidential Information and shall use it only
  ~ in accordance with the terms of the agreements you entered into with Charkey.
  ~
  ~ Charkey MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE,
  ~ EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
  ~ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  ~
  ~ Charkey SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,
  ~ MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  --%>

<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<style>
    .detail {
        word-break: break-all;
    }
</style>
<script src="${ctx}/static/js/jquery-2.0.3.min.js"></script>
<div data-table="table" class="panel">
    <table class="table table-bordered">
        <tbody>

        <tr class="bold info">
            <td colspan="2">
                ${cacheName} 键列表
            </td>
        </tr>

        <c:forEach items="${keys}" var="key">
            <tr>
                <td style="width: 40%">${key}</td>
                <td data-key="${key}">
                    <a class="btn btn-link no-padding btn-details">查看详细</a>
                    <a class="btn btn-link no-padding btn-delete">删除</a>
                </td>
            </tr>
        </c:forEach>

        </tbody>
    </table>
    <br/><br/>
</div>
<script type="text/javascript">
    $(function () {
        $(".btn-details").click(function () {
            var td = $(this).closest("td");
            var key = td.data("key");
            var url = "${ctx}/monitor/ehcache/${cacheName}/" + key + "/details";
            $.getJSON(url, function (data) {
                var detail = td.find(".detail");
                if (detail.length) {
                    detail.remove();
                }
                detail = $("<div class='detail alert alert-block alert-info in fade'></div>");

                var detailInfo = "";
                detailInfo += "命中次数:" + data.hitCount;
                detailInfo += " <br> ";
                detailInfo += "大小:" + data.size;
                detailInfo += " <br> ";
                detailInfo += "最后创建/更新时间:" + data.latestOfCreationAndUpdateTime;
                detailInfo += " <br> ";
                detailInfo += "最后访问时间:" + data.lastAccessTime;
                detailInfo += " <br> ";
                detailInfo += "过期时间:" + data.expirationTime;
                detailInfo += " <br> ";
                detailInfo += "timeToIdle(秒):" + data.timeToIdle;
                detailInfo += " <br> ";
                detailInfo += "timeToLive(秒):" + data.timeToLive;
                detailInfo += " <br> ";
                detailInfo += "version:" + data.version;
                detailInfo += "<br/>";
                detailInfo += "值:" + data.objectValue;
                detailInfo += "<br/><br/>";

                detail.append(detailInfo);
                td.append(detail);
            });
        });

        $(".btn-delete").click(function () {

            var td = $(this).closest("td");
            var key = td.data("key");
            var url = "${ctx}/monitor/ehcache/${cacheName}/" + key + "/delete";
            $.get(url, function (data) {
                td.closest("tr").remove();
            });

        });

        $(".btn-clear").click(function () {
            $.app.confirm({
                title: "确认清空缓存",
                message: "确认清空整个缓存吗？",
                ok: function () {
                    var url = "${ctx}/monitor/ehcache/${cacheName}/clear";
                    $.get(url, function (data) {
                        window.location.reload();
                    });
                }
            });
        });
    });

</script>